{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-06-10 21:55:05.352\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mbyzerllm.utils.connect_ray\u001b[0m:\u001b[36mconnect_cluster\u001b[0m:\u001b[36m37\u001b[0m - \u001b[1mJDK 21 will be used (/Users/allwefantasy/.auto-coder/jdk-21.0.2.jdk/Contents/Home)...\u001b[0m\n",
      "2024-06-10 21:55:05,510\tINFO worker.py:1564 -- Connecting to existing Ray cluster at address: 127.0.0.1:6379...\n",
      "2024-06-10 21:55:05,526\tINFO worker.py:1740 -- Connected to Ray cluster. View the dashboard at \u001b[1m\u001b[32m127.0.0.1:8265 \u001b[39m\u001b[22m\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "21\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-06-10 21:55:10.874\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mautocoder.index.index\u001b[0m:\u001b[36mget_target_files_by_query\u001b[0m:\u001b[36m383\u001b[0m - \u001b[1mFind the related files by query according to the files...\u001b[0m\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[1;3;38;5;200mThought: The user wants to add a new command to the auto-coder tool that supports a specific usage scenario. I need to identify the relevant files that handle command line arguments and commands in the project.\n",
      "Action: get_project_related_files\n",
      "Action Input: {'query': 'command line arguments and commands handling files'}\n",
      "\u001b[0m\u001b[1;3;34mObservation: /Users/allwefantasy/projects/auto-coder/src/autocoder/command_args.py,/Users/allwefantasy/projects/auto-coder/src/autocoder/common/ShellClient.py,/Users/allwefantasy/projects/auto-coder/src/autocoder/common/code_auto_merge.py,/Users/allwefantasy/projects/auto-coder/src/autocoder/common/git_utils.py,/Users/allwefantasy/projects/auto-coder/src/autocoder/index/for_command.py\n",
      "\u001b[0m\u001b[1;3;38;5;200mThought: I have the list of files related to command line arguments and commands handling. Now, I need to generate a YAML configuration file for auto-coder that includes the necessary modifications to support the new command.\n",
      "Action: generate_auto_coder_yaml\n",
      "Action Input: {'yaml_file_name': 'add_new_command', 'yaml_str': 'query: |\\n  关注 command_args.py, ShellClient.py, code_auto_merge.py, git_utils.py, for_command.py 等文件，\\n  添加一个名为 auto-coder agent planner 的新命令，支持 --source_dir, --target_file, --model, --human_as_model, --emb_model, --ray_address 等参数'}\n",
      "\u001b[0m\u001b[1;3;34mObservation: /Users/allwefantasy/projects/auto-coder/actions/079_add_new_command.yml\n",
      "\u001b[0m\u001b[1;3;38;5;200mThought: The YAML configuration file for adding the new command has been successfully generated. I can now inform the user about the generated file and its location.\n",
      "Answer: 已成功生成 YAML 配置文件，文件名为 \"079_add_new_command.yml\"，位于 \"/Users/allwefantasy/projects/auto-coder/actions/\" 目录下。您可以使用以下命令执行此配置文件：\n",
      "```\n",
      "auto-file --file /Users/allwefantasy/projects/auto-coder/actions/079_add_new_command.yml\n",
      "```\n",
      "\u001b[0m"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'已成功生成 YAML 配置文件，文件名为 \"079_add_new_command.yml\"，位于 \"/Users/allwefantasy/projects/auto-coder/actions/\" 目录下。您可以使用以下命令执行此配置文件：\\n```\\nauto-file --file /Users/allwefantasy/projects/auto-coder/actions/079_add_new_command.yml\\n```'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import byzerllm\n",
    "from autocoder.common import AutoCoderArgs\n",
    "from autocoder.agent.planner import Planner\n",
    "from autocoder.utils.tests import get_llm\n",
    "\n",
    "args = AutoCoderArgs(\n",
    "        project_type=\"py\",\n",
    "        source_dir=\"/Users/allwefantasy/projects/auto-coder\",\n",
    "        target_file=\"/Users/allwefantasy/projects/auto-coder/output.txt\",\n",
    "        model=\"deepseek_chat\",\n",
    "        human_as_model=False,\n",
    "        emb_model=\"gpt_emb\",\n",
    "        ray_address=\"auto\"\n",
    "    )\n",
    "\n",
    "llm = get_llm(args)\n",
    "\n",
    "planner = Planner(args, llm)\n",
    "planner.run(\"我希望支持如下使用方式 auto-coder agent planner --source_dir /Users/allwefantasy/projects/auto-coder --target_file /Users/allwefantasy/projects/auto-coder/output.txt --model deepseek_chat --human_as_model False --emb_model gpt_emb --ray_address auto\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-06-10 20:37:34.332\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mbyzerllm.utils.connect_ray\u001b[0m:\u001b[36mconnect_cluster\u001b[0m:\u001b[36m37\u001b[0m - \u001b[1mJDK 21 will be used (/Users/allwefantasy/.auto-coder/jdk-21.0.2.jdk/Contents/Home)...\u001b[0m\n",
      "2024-06-10 20:37:34,552\tINFO worker.py:1564 -- Connecting to existing Ray cluster at address: 127.0.0.1:6379...\n",
      "2024-06-10 20:37:34,553\tINFO worker.py:1582 -- Calling ray.init() again after it has already been called.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "21\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-06-10 20:37:38.522\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mautocoder.index.index\u001b[0m:\u001b[36mget_target_files_by_query\u001b[0m:\u001b[36m383\u001b[0m - \u001b[1mFind the related files by query according to the files...\u001b[0m\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[1;3;38;5;200mThought: The user wants to fix an issue with saving the planner's YAML file. I need to identify the relevant files related to the planner's YAML configuration.\n",
      "Action: get_project_related_files\n",
      "Action Input: {'query': \"planner's YAML configuration files\"}\n",
      "\u001b[0m\u001b[1;3;34mObservation: /Users/allwefantasy/projects/auto-coder/src/autocoder/common/command_templates.py,/Users/allwefantasy/projects/auto-coder/src/autocoder/agent/planner.py\n",
      "\u001b[0m\u001b[1;3;38;5;200mThought: I have identified the relevant files related to the planner's YAML configuration. Now, I need to generate a YAML configuration for auto-coder to fix the saving issue.\n",
      "Action: generate_auto_coder_yaml\n",
      "Action Input: {'yaml_file_name': 'fix_planner_yaml_save', 'yaml_str': 'query: |\\n  关注 /Users/allwefantasy/projects/auto-coder/src/autocoder/common/command_templates.py 和 /Users/allwefantasy/projects/auto-coder/src/autocoder/agent/planner.py 文件，\\n  修复 planner 的 YAML 保存问题'}\n",
      "\u001b[0m\u001b[1;3;34mObservation: /Users/allwefantasy/projects/auto-coder/actions/078_fix_planner_yaml_save.yml\n",
      "\u001b[0m\u001b[1;3;38;5;200mThought: I have successfully generated the YAML configuration file to fix the planner's YAML saving issue. I can now inform the user about the generated file.\n",
      "Answer: 我已经为您生成了一个 YAML 配置文件来修复 planner 的 YAML 保存问题。文件路径为：/Users/allwefantasy/projects/auto-coder/actions/078_fix_planner_yaml_save.yml。您可以使用 auto-coder 工具执行该配置文件来解决问题。\n",
      "\u001b[0m"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'我已经为您生成了一个 YAML 配置文件来修复 planner 的 YAML 保存问题。文件路径为：/Users/allwefantasy/projects/auto-coder/actions/078_fix_planner_yaml_save.yml。您可以使用 auto-coder 工具执行该配置文件来解决问题。'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import byzerllm\n",
    "from autocoder.common import AutoCoderArgs\n",
    "from autocoder.agent.planner import Planner\n",
    "from autocoder.utils.tests import get_llm\n",
    "\n",
    "args = AutoCoderArgs(\n",
    "        project_type=\"py\",\n",
    "        source_dir=\"/Users/allwefantasy/projects/auto-coder\",\n",
    "        target_file=\"/Users/allwefantasy/projects/auto-coder/output.txt\",\n",
    "        model=\"deepseek_chat\",\n",
    "        human_as_model=False,\n",
    "        emb_model=\"gpt_emb\",\n",
    "        ray_address=\"auto\"\n",
    "    )\n",
    "\n",
    "llm = get_llm(args)\n",
    "\n",
    "planner = Planner(args, llm)\n",
    "planner.run(\"修复plannerz中的yaml 保存的问题\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-06-10 22:21:55.026\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mbyzerllm.utils.connect_ray\u001b[0m:\u001b[36mconnect_cluster\u001b[0m:\u001b[36m37\u001b[0m - \u001b[1mJDK 21 will be used (/Users/allwefantasy/.auto-coder/jdk-21.0.2.jdk/Contents/Home)...\u001b[0m\n",
      "2024-06-10 22:21:55,210\tINFO worker.py:1564 -- Connecting to existing Ray cluster at address: 127.0.0.1:6379...\n",
      "2024-06-10 22:21:55,213\tINFO worker.py:1582 -- Calling ray.init() again after it has already been called.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "21\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'auto_merge 接受的参数类型包括 bool 类型和字符串类型。字符串类型的可选值有 wholefile, diff, strict_diff, editblock。如果 bool 类型设置为 true，则等价于 wholefile。'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import byzerllm\n",
    "from autocoder.common import AutoCoderArgs\n",
    "from autocoder.agent.planner import Planner,get_tools\n",
    "from autocoder.utils.tests import get_llm\n",
    "\n",
    "args = AutoCoderArgs(\n",
    "        project_type=\"py\",\n",
    "        source_dir=\"/Users/allwefantasy/projects/auto-coder\",\n",
    "        target_file=\"/Users/allwefantasy/projects/auto-coder/output.txt\",\n",
    "        model=\"deepseek_chat\",\n",
    "        human_as_model=False,\n",
    "        emb_model=\"gpt_emb\",\n",
    "        ray_address=\"auto\",\n",
    "        enable_rag_search= True,\n",
    "        collections=\"auto-coder\"\n",
    "    )\n",
    "\n",
    "llm = get_llm(args)\n",
    "tools = get_tools(args, llm)\n",
    "tools[2].fn(\"auto_merge都有哪些参数\")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "byzerllm",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
